package edu.lhh;

import java.io.IOException;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import edu.lhh.dao.teachtypedao;
import edu.lhh.model.teachtype;

/**
 * Servlet implementation class repwd
 */
@WebServlet("/repwd")
public class repwd extends HttpServlet {
	teachtypedao dao = new teachtypedao();
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public repwd() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
			response.sendRedirect("repassward.jsp");
			
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		String num = request.getParameter("num");
		String ming = new String(request.getParameter("ming").getBytes("ISO-8859-1"),"UTF-8");
		teachtype type = new teachtype();
		try {
			type = dao.findbynum(num);
			if (ming.equals(type.getMing()) && num.equals(type.getNum())){
				request.setAttribute("pwd", type.getPwd());
				request.getRequestDispatcher("FindpwdSuccess.jsp").forward(request, response);
			}
			else{
				response.sendRedirect("FindpwdDefeat.jsp");
			}
			//System.out.println(type.getMing());
			//System.out.println(ming);
			//System.out.println(type.getNum());
			//System.out.println(num);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}

}